import { someFieldStore } from "@/stores/somefield";
import { useStore } from "@/stores/user";
import { getUrlParamValue } from "@/utils/getUrlParams";


const mSomefield = someFieldStore();
const mUser = useStore();


//客服参数
function buildKfUrlParams() {
  const params = new URLSearchParams();

  // 处理用户信息参数
  if (mUser.token?.uid && mUser.token.uid !== '0') {
    params.append('uid', mUser.token.uid);
  }
  if (mUser.token?.user_name && mUser.token.user_name.trim() !== '') {
    params.append('user_name', mUser.token.user_name);
  }

  // 处理game_id (必传)
  const gameId = getUrlParamValue('game_id', mSomefield.clientfields);
  params.append('game_id', gameId || '0');

  // 处理其他可选参数
  const optionalParams = ['role_id', 'role_name', 'server_id', 'server_name','company'];
  optionalParams.forEach(param => {
    const value = getUrlParamValue(param, mSomefield.clientfields);
    if (value && value !== '0' && value.trim() !== '') {
      params.append(param, value);
    }
  });

  return params.toString();
}



const API = {
    faqList:`/sdk/service/faq/list`,  //获取faq分类树状
    faqDetail:`/sdk/service/faq/detail`, //faq详情
    faqHotList:`/sdk/service/faq/hot_list`, //faq热门
    getKfUrl: () => `${import.meta.env.VITE_API_URL}/sdk/sys/cs?${buildKfUrlParams()}` // 客服链接动态生成
}


export default API;